<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑页面</title>

    <script src="../js/layui/layui.js"></script>
    <link rel="stylesheet" href="../js/layui/css/layui.css"/>
    <script src="../js/jquery/jquery-1.9.1.js"></script>
</head>
<body>
<form class="layui-form" id="messageForm" method="post" lay-filter="companyFilter">
    <div class="layui-form-item">
        <div class="layui-inline">
            <input  type="hidden" name="id" id="id">
            <label class="layui-form-label">公司名称:</label>
            <div class="layui-input-block">
                <input type="text" name="comName" autocomplete="off" placeholder="公司名称" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">公司地址:</label>
            <div class="layui-input-inline">
                <input type="text" name="address" placeholder="公司地址" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">执照编号:</label>
            <div class="layui-input-inline">
                <input type="text" name="zhiZhaoHao"  placeholder="执照号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="zhiZhaoImg">上传执照</button>
            <div class="layui-upload-list"><!--layui-hide-->
                <img class="layui-upload-img" id="zhiZhao" style="width: 200px">
                <input type="text" id="hadeimg" name="zhiZhao" autocomplete="off" class="layui-hide" >
                <p id="shibai"></p>
            </div>
        </div>
    </div>
</form>
</body>
<script>

    layui.use(['form', 'layedit', 'laydate','upload'], function() {
        var form = layui.form,
            layedit = layui.layedit,
            laydate = layui.laydate,
            upload = layui.upload,
            layer = parent.layer === undefined ? layui.layer : parent.layer;
        //日期
        laydate.render({
            elem: '#date',
            type:'datetime'
        });
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#zhiZhaoImg',
            url: '../company/upload',
            before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#zhiZhao').attr('src', result); //图片链接（base64）
                });
            },
            done: function (res) {
                //如果上传失败
                $('#hadeimg').val(res.img);
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
            },
            error: function () {
                //演示失败状态，并实现重传
                var shibai = $('#shibai');
                shibai.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                shibai.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        })
    })

    function editForm(data) {
        layui.use(['form'], function() {
            var form = layui.form;
            form.val("companyFilter",{
                id:data.id,
                comName:data.comName,
                address:data.address,
                zhiZhao:data.zhiZhao,
                zhiZhaoHao:data.zhiZhaoHao,
            })
        })
    }

    function saveCompanyMessage() {
        alert("a");
        $.ajax({
            url:'../company/saveCompanyMessage',
            data:$("#messageForm").serialize(),
            type:'post',
            dataType:'json',
            success:function (data) {
                if(!data){
                    layer.alert("修改失败",{icon:0})
                }
            }
        })
    }
</script>
</html>